﻿@page "/RkPage"
@inject RkServer rkServer
@inject FinshGetServer finshGetServer
@using System.ComponentModel
@using AntDesign.TableModels
@inject ModalService _modalService
@inject MessageService _message
<h3>成品入库</h3>
<div>
    <Row>
        <Col Span="24">请选择成品取料点</Col>
    </Row>
    <Row>
        <Col Span="24">
        <Select style="width:100%" DataSource="@DataList"
                AllowClear="true"
                ValueOnClear="@(0)"
                @bind-Value="@selet"
                ValueName="@nameof(FinishedGet_Entity.Deviceid)"
                LabelName="@nameof(FinishedGet_Entity.Remark)">
        </Select>
        </Col>
    </Row>
    <Row>
        <Col Span="24">扫码输入框</Col>
    </Row>
    <Row>
        <Col Span="24">
            @* <Input type="" style="width:100%" @bind-Value="@ss" @onkeydown="Change" />*@
        <input @ref="input" Type="text" style="width:100%;" placeholder="Basic usage" @bind:event="oninput" @bind="@ss" @onkeydown="Change" />

        </Col>
    </Row>
    <Row>
        <Col Span="24">批号</Col>
    </Row>
    <Row>
        <Col Span="24">
        <Input style="width:100%" Placeholder="Basic usage" @bind-Value="@Batch" />
        </Col>
    </Row>
    <Row>
        <Col Span="24">
        <br>
        <Button style="width:100%" Type="@ButtonType.Primary">解析二维码</Button>
        <br>
        <br>
        <Button style="width:100%" Type="@ButtonType.Primary" @onclick="@Creat">提交入库任务</Button>
        <br>
        <br>
        <Button style="width:100%" Type="@ButtonType.Primary" @onclick="@Creat2">提交直接出库任务</Button>
        </Col>
    </Row>
</div>

@code {
    ObservableCollection<FinishedGet_Entity> DataList { get; set; } = new ObservableCollection<FinishedGet_Entity>();
    int selet { get; set; } = 0;
    string Batch { get; set; }
    string ss { get; set; }
    private ElementReference input;
    protected override async Task OnInitializedAsync()
    {
        var list = await finshGetServer.Getlist();
        if (list != null)
        {
            DataList.Clear();
            foreach (var item in list)
            {
                DataList.Add(item);
            }
        }
        base.OnInitialized();
    }
    private void Change(KeyboardEventArgs e)
    {
        try
        {
            if (e.Key == "Enter")
            {
                if (!string.IsNullOrEmpty(ss))
                {

                    var a = ss.Split(',');
                    Batch = a[0];
                    //for (int i = 0; i < a.Length; i++)
                    //{
                    //    if (a[i].Contains("Flot"))
                    //    {
                    //        Batch = a[i].Remove(0, 4);
                    //    }
                    //}
                }
            }
            
        }
        catch (Exception)
        {


        }


    }
    private async Task Creat()
    {
        await _modalService.ConfirmAsync(new ConfirmOptions()
            {
                Title = "提示",
                Icon =@<Icon Type="exclamation-circle" Theme="Outline"></Icon>,
           OkText = "确认",
           OnOk = async (e) =>
           {

               var aa = await rkServer.TaskCreat(selet, Batch);
               _message.Info(aa);


           },
           CancelText = "取消",
           Content = "是否提交？",
       });
        ss = "";
        Batch = "";
        input.FocusAsync();


    }
    private async Task Creat2()
    {
        _modalService.Confirm(new ConfirmOptions()
            {
                Title = "提示---直接出库请先手动更新该批号入库单仓位",
                Icon =@<Icon Type="exclamation-circle" Theme="Outline"></Icon>,
            OkText = "确认",
            OnOk = async (e) =>
            {
                var aa = await rkServer.TaskCreatOther(selet, Batch);
                _message.Info(aa);
            },
            CancelText = "取消",
            Content = "是否提交？",
        });

        ss = "";
        Batch = "";
        input.FocusAsync();
    }
}
